home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Readers / DoubleClick / Euclid.c < prev    next >
C/C++ Source or Header  |  1997-10-31  |  526b  |  39 lines

  1.  
  2. /* Euclid's Algorithm */
  3.  
  4. #include <stdio.h>
  5. #include <exec/types.h>
  6.  
  7. /*
  8.     a,b are initial numbers
  9.     A[] is array to store numbers
  10.     n is counter
  11. */
  12. ULONG a,b,A[200];
  13. int n;
  14.  
  15. void main()
  16. {
  17.     do
  18.     {
  19.         printf("Please Enter a Number...\n");
  20.         scanf("%d",&a);
  21.         if (a==0)
  22.             break;
  23.         printf("and Another Number...\n");
  24.         scanf("%d",&b);
  25.         A[0]=a;
  26.         A[1]=b;
  27.         n=0;
  28.     
  29.         do
  30.         {
  31.             if (A[n] % A[n+1] == 0)
  32.                 break;
  33.             A[n+2]=A[n] % A[n+1];
  34.             n++;
  35.         } while (1);
  36.         printf("\nThe hcf of %d and %d is %d\n\n",a,b,A[n+1]);
  37.     } while (1);
  38. }
  39.